package org.itzheng.myrxframe.upt;

import org.itzheng.myrxframe.http.ApiUrl;
import org.itzheng.myrxframe.http.bean.RowsBean;
import org.itzheng.myrxframe.http.bean.abase.BaseResult;

import java.util.Map;

import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.HeaderMap;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Streaming;
import retrofit2.http.Url;

/**
 * Title:测试Retrofit接口<br>
 * Description: <br>
 *
 * @email ItZheng@ZoHo.com
 * Created by itzheng on 2019-4-9.
 */
public interface UtpApiService {
    /**
     * 通过Url加载内容
     *
     * @param url
     * @return
     */
    @GET
    Observable<ResponseBody> getUrl(@Url String url);

    /**
     * 下载文件
     * 来自https://blog.csdn.net/impure/article/details/79658098
     *
     * @Streaming 这个注解必须添加，否则文件全部写入内存，文件过大会造成内存溢出
     */
    @Streaming
    @GET
    Observable<ResponseBody> download(@Header("RANGE") String start, @Url String url);

    //

    /**
     * 上传一个图片：亲测可用
     * RequestBody reqFile = RequestBody.create(MediaType.parse("image/*"), file);
     * MultipartBody.Part body = MultipartBody.Part.createFormData("file", file.getName(), reqFile);
     *
     * @param headers
     * @param file
     * @return
     */
    @Multipart
    @POST("file/upload")
    Observable<ResponseBody> uploadImage(@HeaderMap Map<String, String> headers, @Part MultipartBody.Part file);

    /**
     * 多个文件上传：亲测可用
     * MultipartBody.Builder builder = new MultipartBody.Builder()
     * .setType(MultipartBody.FORM)
     * .addFormDataPart("file", "_1_" + file.getName(), RequestBody.create(MediaType.parse("image/*"), file))
     * .addFormDataPart("file", "_2_" + file.getName(), RequestBody.create(MediaType.parse("image/*"), file));
     *
     * @param headers
     * @param file
     * @return
     */
    @POST("file/upload")
    Observable<ResponseBody> uploadImage(@HeaderMap Map<String, String> headers, @Body RequestBody file);
}
